/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import { concat } from "lodash-es";
import { page as merchantPage } from "$/attractions/commerce/api/commerceMerchant.ts";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "商户名称",
      prop: "merchant_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: merchantPage,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.merchant_name || `商户名称${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择商户名称",
        clearable: true,
        multiple: false,
      },
      itemProps: { rules: [{ required: true, message: "请选择商户名称" }] },
    },
    {
      label: "客户姓名",
      prop: "customer_name",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "客户姓名" }) },
      itemProps: { rules: [{ required: true, message: "请输入客户姓名" }] },
    },
    // {
    //   label: "测试id",
    //   prop: "id",
    //   render: "input",
    //   renderProps: { placeholder: t("form.pleaseInput", { msg: "测试id" }) },
    // },
    {
      label: "客户电话",
      prop: "customer_phone",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "客户电话" }) },
    },
    {
      label: "客户地址",
      prop: "customer_address",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "客户地址" }) },
    },
    {
      label: "订单来源",
      prop: "order_source",
      render: () => MaDictSelect,
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: "订单来源",
        }),
        data: [
          { label: "线上下单", value: 1 },
          { label: "现场订单", value: 2 },
        ],
        clearable: true,
        multiple: false,
      },
      itemProps: {
        rules: [{ required: true, message: "请选择订单来源" }],
      },
    },
    {
      label: "订单状态",
      prop: "order_status",
      render: () => MaDictSelect,
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: "订单状态",
        }),
        data: [
          { label: "待支付", value: 1 },
          { label: "待发货", value: 2 },
          { label: "待收货", value: 3 },
          { label: "已完成", value: 4 },
          { label: "已取消", value: 5 },
        ],
        clearable: true,
        multiple: false,
      },
      itemProps: {
        rules: [{ required: true, message: "请选择订单状态" }],
      },
    },
    {
      label: "订单总金额",
      prop: "total_amount",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "订单总金额" }),
      },
      itemProps: { rules: [{ required: true, message: "请输入订单总金额" }] },
    },
    {
      label: "优惠",
      prop: "discount_amount",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "优惠" }) },
    },
    {
      label: "实付金额",
      prop: "actual_amount",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "实付金额" }) },
      itemProps: { rules: [{ required: true, message: "请输入实付金额" }] },
    },
    {
      label: "付款方式",
      prop: "payment_method",
      render: () => MaDictSelect,
      renderProps: {
        placeholder: t("form.pleaseSelect", { msg: "付款方式" }),
        data: [
          { label: "银行转账", value: 1 },
          { label: "微信支付", value: 2 },
          { label: "支付宝支付", value: 3 },
          { label: "现金", value: 4 },
          { label: "其他付款方式", value: 5 },
        ],
        clearable: true,
      },
      itemProps: { rules: [{ required: true, message: "请选择付款方式" }] },
    },
    {
      label: "支付时间",
      prop: "payment_time",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "支付时间" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      mode: "date",
      showTime: true,
    },
    {
      label: "发货时间",
      prop: "delivery_time",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "发货时间" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      mode: "date",
      showTime: true,
    },
    {
      label: "快递公司",
      prop: "express_company",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "快递公司" }) },
    },
    {
      label: "快递单号",
      prop: "express_id",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "快递单号" }) },
    },
    {
      label: "快递信息",
      prop: "express_info",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "快递信息" }) },
    },
    {
      label: "取消原因",
      prop: "cancel_reason",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "取消原因" }) },
    },
    {
      label: "取消时间",
      prop: "cancel_time",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "取消时间" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      mode: "date",
      showTime: false,
    },
    {
      label: "完成时间",
      prop: "finish_time",
      render: "DatePicker",
      renderProps: {
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
        placeholder: t("form.pleaseInput", { msg: "完成时间" }),
      },
      mode: "date",
      showTime: false,
    },
  ]);
}
